import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
import { getUserList } from '../api/user'



// 异步请求方式2
export const queryAiSiteList = ({page, pageSize, question}) => {
    console.log('queryAiSiteList question=', question)


    return async (dispatch, getState) => {
        let {list, total} = await getUserList({
            page, pageSize, question
        })
        
        dispatch(setAiSiteList(list))
        dispatch(setTotal(total))
    }
}


export const aiSiteSlice = createSlice({
    name: 'aiSite',

    initialState: {
        list: [],
        total: 0,
        page: 0,
        pageSize: 25,

        // pageState: {
        //     list: [],
        //     total: 0,
        //     page: 0,
        //     pageSize: 25,
        // }
    },

    // 同步方法的action操作
    reducers: {

        setAiSiteList: (state, action) => {
            console.log('setAiSiteList action=', action)
            state.list = action.payload
        },

        setTotal: (state, action) => {
            state.total = action.payload
        },
        setPage: (state, action) => {
            console.log('setPage action=', action)
            state.page = action.payload
        },
        setPageSize: (state, action) => {
            console.log('setPageSize action=', action)
            state.pageSize = action.payload
        },


        // setAiSiteList2: (state, action) => {
        //     console.log('setAiSiteList action=', action)
        //     state.pageState.list = action.payload
        // },

        // setTotal2: (state, action) => {
        //     state.pageState.total = action.payload
        // },
        // setPage2: (state, action) => {
        //     console.log('setPage action=', action)
        //     state.pageState.page = action.payload
        // },
        // setPageSize2: (state, action) => {
        //     console.log('setPageSize action=', action)
        //     state.pageState.pageSize = action.payload
        // },
    }

})



export const { setAiSiteList, setTotal, setPage, setPageSize } = aiSiteSlice.actions

export default aiSiteSlice.reducer
